package com.sebiotec.manager.ui.activity;

import android.annotation.SuppressLint;
import android.text.InputType;
import android.text.TextUtils;
import android.text.method.DigitsKeyListener;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.lifecycle.ViewModelProviders;

import com.allen.library.RxHttpUtils;
import com.sebiotec.basecommon.utils.base.BaseActivity;
import com.sebiotec.basecommon.utils.constant.SjmConstant;
import com.sebiotec.basecommon.utils.tools.ActivityTool;
import com.sebiotec.basecommon.utils.tools.SPUtils;
import com.sebiotec.basecommon.utils.tools.TimeTool;
import com.sebiotec.basecommon.utils.tools.TimeUtil;
import com.sebiotec.basecommon.utils.tools.ToastTool;

import com.sebiotec.manager.R;

import com.sebiotec.manager.R2;
import com.sebiotec.manager.adapt.SearchAdapter;
import com.sebiotec.manager.model.event.RefEvent;
import com.sebiotec.manager.model.response.AddNocationResponse;
import com.sebiotec.manager.model.response.LocationsResponse;
import com.sebiotec.manager.ui.view.SearchWather;
import com.sebiotec.manager.viewmodel.QuickAddViewModel;
import com.xuexiang.xui.widget.button.ButtonView;
import com.xuexiang.xui.widget.picker.widget.OptionsPickerView;
import com.xuexiang.xui.widget.picker.widget.TimePickerView;
import com.xuexiang.xui.widget.picker.widget.builder.OptionsPickerBuilder;
import com.xuexiang.xui.widget.picker.widget.builder.TimePickerBuilder;
import com.xuexiang.xui.widget.picker.widget.listener.OnOptionsSelectListener;
import com.xuexiang.xui.widget.picker.widget.listener.OnTimeSelectChangeListener;
import com.xuexiang.xui.widget.picker.widget.listener.OnTimeSelectListener;

import com.xuexiang.xui.widget.toast.XToast;

import org.greenrobot.eventbus.EventBus;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;

public class QuickAddActivity extends BaseActivity {
    @BindView(R2.id.qk_back)
    ImageView qkBack;
    @BindView(R2.id.tv_save)
    TextView tvSave;
    @BindView(R2.id.et_getinfo)
    EditText etGetinfo;
    @BindView(R2.id.btn_get_info)
    ButtonView btnGetInfo;
    @BindView(R2.id.iv_date)
    ImageView ivDate;
    @BindView(R2.id.et_date)
    EditText etDate;
    @BindView(R2.id.et_time)
    EditText etTime;
    @BindView(R2.id.auto_tv1)
    AutoCompleteTextView autoTv1;
    @BindView(R2.id.auto_tv2)
    AutoCompleteTextView autoTv2;
    @BindView(R2.id.et_other)
    EditText etOther;
    @BindView(R2.id.auto_tv3)
    AutoCompleteTextView autoTv3;
    @BindView(R2.id.auto_tv4)
    AutoCompleteTextView viewById;
    @BindView(R2.id.et_Passenger)
    EditText etPassenger;
    @BindView(R2.id.rl_pax)
    RelativeLayout rlPax;
    @BindView(R2.id.tv_lug)
    TextView tvLug;
    @BindView(R2.id.rl_lug)
    RelativeLayout rlLug;
    @BindView(R2.id.et_vehicle)
    EditText etVehicle;
    @BindView(R2.id.cb_signboard)
    CheckBox cbSignboard;
    @BindView(R2.id.cb_round_trip)
    CheckBox cb_round_trip;

    @BindView(R2.id.et_signboard)
    EditText etSignboard;
    @BindView(R2.id.et_remark)
    EditText etRemark;
    @BindView(R2.id.tv_pax)
    TextView tvPax;

    @BindView(R2.id.et_itinerary)
    EditText etItinerary;
    @BindView(R2.id.et_card_type)
    EditText etCardType;
    @BindView(R2.id.et_pay_id)
    EditText etPayId;
    private TimePickerView mTimePicker;
    private TimePickerView mpickUpTime;

    private QuickAddViewModel mQuickAddViewModel;
    private int mChargedTypeOption = 0;
    private OptionsPickerView<Object> pvOptions;
    private OptionsPickerView<Object> mVehicleType;
    private int mVehicleTypeOption = 0;
    private   int RoundTrip;
    private OptionsPickerView<Object> mLugType;
    private int mLugTypeOptions = 0;
    private OptionsPickerView<Object> mChargedType;
    private int mPaxTypeOptions = 0;
    private OptionsPickerView<Object> mPaxType;

    private String ChargedTypeId;
    private String FromLocId;

    private String PickupFrom;
    private String ToLocId;
    private String Destination;
    private String VechileTypeId;
    private String VechileType;
    private ArrayAdapter<String> Destinationadapter;
    private ArrayAdapter<String> PickUpFromadapter;
    private Map<String, List<LocationsResponse>> collectDestinationData;
    private Map<String, List<LocationsResponse>> PickUpFromcollect;
    private Map<String, List<LocationsResponse>> collectChargedTypeData;
    private Map<String, List<LocationsResponse>> collectVehicleTypeData;
    private String LoginId;
    private int mAddTypeOption=0;

    private Date nowDate;
    private Map<String, List<AddNocationResponse>> Nocationalcollect;
    private OptionsPickerView<Object> mPickUpFrom;
    private int mPickUpFromOption;
    private int mDestinationOption;
    private OptionsPickerView<Object> mDestination;
    private OptionsPickerView<Object> mAddNocational;
    private int mAddNocationalOption;
    private  String mCurrentTime;
    private  String mlaterTime;
    private SimpleDateFormat df;
    private OptionsPickerView<Object> mCadType;
    private int mCadTypeOptions;
    private String trim;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_quick_add;
    }

    @Override
    protected void initUI() {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy/MM/dd");

        Calendar c = Calendar.getInstance();




        etDate.setText( sf.format(c.getTime()));
        nowDate = new Date();
        mQuickAddViewModel = ViewModelProviders.of(this).get(QuickAddViewModel.class);
//        etGetinfo.setKeyListener(new DigitsKeyListener() {
//            @Override
//            public int getInputType() {
//                return InputType.TYPE_TEXT_VARIATION_PASSWORD;
//            }
//
//            @Override
//            protected char[] getAcceptedChars() {
//                char[] ac = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
//                return ac;
//            }
//        });
        etGetinfo.addTextChangedListener(new SearchWather(etGetinfo));
        etPayId.addTextChangedListener(new SearchWather(etPayId));

        //初始化時間選擇器
        pickUpDate();
        pickUpTime();


    }

    private void LugType(final int[] o) {
        mLugType = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                tvLug.setText(o[options1] + "");
                mLugTypeOptions = options1;
//                LocalManageUtil.saveSelectLanguage(QuickAddActivity.this, 3);
//                ActivityTool.getInstance().finishAllActivities();
//                ARouter.getInstance().build("/App/MainActivity").navigation();

            }
        }).setCancelText(getString(R.string.date_dis))//取消按钮文字
                .setSubmitText(getString(R.string.sure))//确认按钮文字
                .setTitleText(getString(R.string.lug))
                .setSubCalSize(16)
                .setSubCalSize(16)
                .setSelectOptions(mLugTypeOptions)
                .build();
        String[] strs = new String[o.length];
        for (int i = 0; i < o.length; i++) {
            strs[i] = String.valueOf(o[i]);
        }
        mLugType.setPicker(strs);

    }


    private void CadType(final String[] o) {
        mCadType = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                etCardType.setText(o[options1] + "");
                mCadTypeOptions = options1;
                trim=options1+1+"";
                Log.e("options1",options1+"");
                Log.e("options1",o[options1] + "");
//                LocalManageUtil.saveSelectLanguage(QuickAddActivity.this, 3);
//                ActivityTool.getInstance().finishAllActivities();
//                ARouter.getInstance().build("/App/MainActivity").navigation();

            }
        }).setCancelText(getString(R.string.date_dis))//取消按钮文字
                .setSubmitText(getString(R.string.sure))//确认按钮文字
                .setTitleText(getString(R.string.card_type_title))
                .setSubCalSize(16)
                .setSubCalSize(16)
                .setSelectOptions(mCadTypeOptions)
                .build();


        String[] strs = new String[o.length];
        for (int i = 0; i < o.length; i++) {
            strs[i] = o[i];
        }
        mCadType.setPicker(strs);

    }

    private void PaxType(final int[] o) {
        mPaxType = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                tvPax.setText(o[options1] + "");
                mPaxTypeOptions = options1;
//                LocalManageUtil.saveSelectLanguage(QuickAddActivity.this, 2);
//                ActivityTool.getInstance().finishAllActivities();
//                ARouter.getInstance().build("/App/MainActivity").navigation();
            }
        }).setCancelText(getString(R.string.date_dis))//取消按钮文字
                .setSubmitText(getString(R.string.sure))//确认按钮文字
                .setTitleText(getString(R.string.pax))
                .setSubCalSize(16)
                .setSubCalSize(16)
                .setSelectOptions(mPaxTypeOptions)
                .build();
        String[] strs = new String[o.length];
        for (int i = 0; i < o.length; i++) {
            strs[i] = String.valueOf(o[i]);
        }
        mPaxType.setPicker(strs);

    }

    private void ChargedType(final String[] o) {
        mChargedType = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                autoTv3.setText(o[options1]);
                mChargedTypeOption = options1;


                ChargedTypeId = collectChargedTypeData.get(o[options1]).get(0).getCode().toString();

            }
        }).setCancelText(getString(R.string.date_dis))//取消按钮文字
                .setSubmitText(getString(R.string.sure))//确认按钮文字
                .setTitleText(getString(R.string.charged_types))
                .setSelectOptions(mChargedTypeOption)
                .setSubCalSize(16)
                .setSubCalSize(16)
                .build();
        mChargedType.setPicker(o);

    }

    private void VehicleType(final String[] o) {
        mVehicleType = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                etVehicle.setText(o[options1]);
                mVehicleTypeOption = options1;
                VechileTypeId = collectVehicleTypeData.get(o[options1]).get(0).getCode().toString();
            }
        }).setCancelText(getString(R.string.date_dis))//取消按钮文字
                .setSubmitText(getString(R.string.sure))//确认按钮文字
                .setTitleText(getString(R.string.vehicletype))
                .setSubCalSize(16)
                .setSubCalSize(16)
                .setSelectOptions(mVehicleTypeOption)
                .build();
        mVehicleType.setPicker(o);

    }

    private void pickUpDate() {

        mTimePicker = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelected(Date date, View v) {

                String dateByDatesHNowDate = TimeUtil.getDateByDatesH(nowDate);
                String dateByDatesHSelelctDate = TimeUtil.getDateByDatesH(date);

                int timeCompareSize = TimeUtil.getTimeCompareSizeBook(dateByDatesHNowDate, dateByDatesHSelelctDate);
                if (timeCompareSize==1) {
                    //早于今天
                    XToast.error(QuickAddActivity.this, getString(R.string.before_time)).show();
                } else {
                    etDate.setText(TimeUtil.getDateByDates(date));
                }
            }
        })
                .setTimeSelectChangeListener(new OnTimeSelectChangeListener() {

                    @Override
                    public void onTimeSelectChanged(Date date) {
                        //不能早於當天
//                        Date nowDate = new Date();
//                        boolean before = date.before(nowDate);
//                        if (before) {
//                            //早于今天
//                            XToast.error(QuickAddActivity.this, getString(R.string.before_time)).show();
//                        }
                    }
                })

                .setType(new boolean[]{true, true, true, false, false, false})
                .isCenterLabel(false)
                .setSubCalSize(16)
                .setSubCalSize(16)
                .setCancelText(getString(R.string.date_dis))//取消按钮文字
                .setSubmitText(getString(R.string.sure))//确认按钮文字
                .setLabel("", "", "", "", "", "")
                .setTitleText(getString(R.string.date_select))
                .build();

    }

    private void pickUpTime() {
        mpickUpTime = new TimePickerBuilder(this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelected(Date date, View v) {
                String m="00";
                String dateByDatesHNowDate = TimeUtil.getDateByDatesH(nowDate);
                String dateByDatesHSelelctDate = etDate.getText().toString() + " " + TimeUtil.getDateByDateHour(date);
                if (TimeUtil.getDateByDateMin(date).equals("01")){
                    m="10";
                }else if(TimeUtil.getDateByDateMin(date).equals("02")){
                    m="20";
                }else if(TimeUtil.getDateByDateMin(date).equals("03")){
                    m="30";
                }else if(TimeUtil.getDateByDateMin(date).equals("04")){
                    m="40";
                }else if(TimeUtil.getDateByDateMin(date).equals("05")){
                    m="50";
                }else{
                    m="00";
                }

                String hour = TimeUtil.getDateByDateHours(date);
                String format = etDate.getText().toString()+" "+hour+":"+m;
                Calendar c = Calendar.getInstance();
                Calendar c1 = Calendar.getInstance();
                df = new SimpleDateFormat("yyyy/MM/dd HH:mm");
                mCurrentTime=df.format(c1.getTime());

                c.add(Calendar.MINUTE, SPUtils.get(SjmConstant.SINTERVALMINS,0));
                String dateByDateHour = TimeUtil.getDateByDateHour(c.getTime());
                if (TimeUtil.getDifferentTimeMin(mCurrentTime,format)>=SPUtils.get(SjmConstant.SINTERVALMINS,0)){
                    etTime.setText(hour+":"+m);
                }else{
                    XToast.error(QuickAddActivity.this, getString(R.string.before_times)).show();
                }

//                int timeCompareSize = TimeUtil.getTimeCompareSizeBook(dateByDatesHNowDate, dateByDatesHSelelctDate);
//                if (timeCompareSize==1) {
//                    //早于今天
//                    XToast.error(QuickAddActivity.this, getString(R.string.before_time)).show();
//
//                } else if (timeCompareSize==0){
//                    XToast.error(QuickAddActivity.this, getString(R.string.before_time)).show();
//
//                }else{
//                    etTime.setText(hour+":"+m);
//                }

            }
        })
                .setTimeSelectChangeListener(new OnTimeSelectChangeListener() {
                    @Override
                    public void onTimeSelectChanged(Date date) {

                    }
                })

                .setType(new boolean[]{false, false, false, true, true, false})
                .isCenterLabel(false)
                .setSubCalSize(16)
                .setSubCalSize(16)
                .setCancelText(getString(R.string.date_dis))//取消按钮文字
                .setSubmitText(getString(R.string.sure))//确认按钮文字
                .setLabel("", "", "", "", "", "")
                .setTitleText(getString(R.string.select_time))
                .build();
    }


    private void PickUpFrom(final String[] o) {
        mPickUpFrom = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
//                if (o[options1].equals(autoTv2.getText().toString().trim())) {
//                    XToast.error(QuickAddActivity.this, getString(R.string.error_address)).show();
//                    autoTv1.setText("");
//                }else{
                autoTv1.setText(o[options1]);
                mPickUpFromOption = options1;
                PickupFrom=o[options1];
                FromLocId = PickUpFromcollect.get(o[options1]).get(0).getCode().toString();



            }
        }).setCancelText(getString(R.string.date_dis))//取消按钮文字
                .setSubmitText(getString(R.string.sure))//确认按钮文字
                .setTitleText(getString(R.string.PickupFrom))
                .setSelectOptions(mPickUpFromOption)
                .setSubCalSize(16)
                .setSubCalSize(16)
                .build();
        mPickUpFrom.setPicker(o);

    }


    private void Destination(final String[] o) {
        mDestination = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
//                if (o[options1].equals(autoTv1.getText().toString().trim())) {
//                    XToast.error(QuickAddActivity.this, getString(R.string.error_address)).show();
//                    autoTv2.setText("");
//                }else{
                autoTv2.setText(o[options1]);
                mDestinationOption = options1;

                Destination=o[options1];
                ToLocId = collectDestinationData.get(o[options1]).get(0).getCode().toString();
//                }


            }
        }).setCancelText(getString(R.string.date_dis))//取消按钮文字
                .setSubmitText(getString(R.string.sure))//确认按钮文字
                .setTitleText(getString(R.string.destinations))
                .setSelectOptions(mDestinationOption)
                .setSubCalSize(16)
                .setSubCalSize(16)
                .build();
        mDestination.setPicker(o);

    }


    private void AddNocational(final String[] o) {
        mAddNocational = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
            @Override
            public void onOptionsSelect(int options1, int options2, int options3, View v) {
                viewById.setText(o[options1]);
                mAddNocationalOption = options1;


                LoginId = Nocationalcollect.get(o[options1]).get(0).getLoginId().toString();

            }
        }).setCancelText(getString(R.string.date_dis))//取消按钮文字
                .setSubmitText(getString(R.string.sure))//确认按钮文字
                .setTitleText(getString(R.string.notification))
                .setSelectOptions(mAddNocationalOption)
                .setSubCalSize(16)
                .setSubCalSize(16)
                .build();
        mAddNocational.setPicker(o);

    }

    @Override
    protected void initData() {
//        mQuickAddViewModel.PickUpFromData(new MyDataCallBack<Object>() {
//            @Override
//            public void onDataSuccessCallBack(Object o) {
//                ArrayList<String> list = new ArrayList();
//                PickUpFromcollect = (Map<String, List<LocationsResponse>>) o;
//                for (Map.Entry<String, List<LocationsResponse>> entry : PickUpFromcollect.entrySet()) {
//                    String mapKey = entry.getKey();
//                    list.add(mapKey);
//                }
//                int size = list.size();
//                String[] array = (String[]) list.toArray(new String[size]);
//
//                PickUpFromadapter = new ArrayAdapter<String>(QuickAddActivity.
//                        this, android.R.layout.simple_dropdown_item_1line, array);
//                autoTv1.setAdapter(PickUpFromadapter);
//
//            }
//
//            @Override
//            public void onDataFailCallBack(Object o) {
//
//            }
//        });
//        mQuickAddViewModel.DestinationData(new MyDataCallBack<Object>() {
//            @Override
//            public void onDataSuccessCallBack(Object o) {
//
//                ArrayList<String> list = new ArrayList();
//                collectDestinationData = (Map<String, List<LocationsResponse>>) o;
//                for (Map.Entry<String, List<LocationsResponse>> entry : collectDestinationData.entrySet()) {
//                    String mapKey = entry.getKey();
//                    list.add(mapKey);
//                }
//                int size = list.size();
//                String[] array = (String[]) list.toArray(new String[size]);
//                Destinationadapter = new ArrayAdapter<String>(QuickAddActivity.
//                        this, android.R.layout.simple_dropdown_item_1line, array);
//                autoTv2.setAdapter(Destinationadapter);
//
//            }
//
//            @Override
//            public void onDataFailCallBack(Object o) {
//
//            }
//        });
//        mQuickAddViewModel.AddNocational(new MyDataCallBack<Object>() {
//            @Override
//            public void onDataSuccessCallBack(Object o) {
//               Nocationalcollect = (Map<String, List<AddNocationResponse>>) o;
//                ArrayList<String> list = new ArrayList();
//                for (Map.Entry<String, List<AddNocationResponse>> entry : Nocationalcollect.entrySet()) {
//                    String mapKey = entry.getKey();
//                    list.add(mapKey);
//                }
//                int size = list.size();
//                String[] array = (String[]) list.toArray(new String[size]);
//                ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter<>(QuickAddActivity.
//                        this, android.R.layout.simple_dropdown_item_1line, array);
//                viewById.setAdapter(stringArrayAdapter);
//            }
//
//
//
//            @Override
//            public void onDataFailCallBack(Object o) {
//
//            }
//        });
//
//        mQuickAddViewModel.VehicleTypeData(new MyDataCallBack<Object>() {
//            @Override
//            public void onDataSuccessCallBack(Object strings) {
//                ArrayList<String> list = new ArrayList();
//                collectVehicleTypeData = (Map<String, List<LocationsResponse>>) strings;
//                for (Map.Entry<String, List<LocationsResponse>> entry : collectVehicleTypeData.entrySet()) {
//                    String mapKey = entry.getKey();
//                    list.add(mapKey);
//                }
//                int size = list.size();
//                String[] array = (String[]) list.toArray(new String[size]);
//
//                VehicleType(array);
//            }
//
//            @Override
//            public void onDataFailCallBack(Object strings) {
//
//            }
//        });
//        mQuickAddViewModel.ChargedTypeData(new MyDataCallBack<Object>() {
//            @Override
//            public void onDataSuccessCallBack(Object o) {
//                ArrayList<String> list = new ArrayList();
//                collectChargedTypeData = (Map<String, List<LocationsResponse>>) o;
//                for (Map.Entry<String, List<LocationsResponse>> entry : collectChargedTypeData.entrySet()) {
//                    String mapKey = entry.getKey();
//                    list.add(mapKey);
//                }
//                int size = list.size();
//                String[] array = (String[]) list.toArray(new String[size]);
//
//                ChargedType(array);
//            }
//
//            @Override
//            public void onDataFailCallBack(Object o) {
//
//            }
//        });
        mQuickAddViewModel.InitData(new QuickAddViewModel.MyDataCallBack<Object>() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                Map<String, Object> stringObjectMap =(Map<String, Object>)o;
                ArrayList<String> list = new ArrayList();
                PickUpFromcollect = (Map<String, List<LocationsResponse>>) stringObjectMap.get("1");
                for (Map.Entry<String, List<LocationsResponse>> entry : PickUpFromcollect.entrySet()) {
                    String mapKey = entry.getKey();
                    list.add(mapKey);
                }
                int size = list.size();
                String[] array = (String[]) list.toArray(new String[size]);
                SearchAdapter<String> stringArrayAdapterss = new SearchAdapter<String>(QuickAddActivity.this, android.R.layout.simple_dropdown_item_1line, list,10);
                autoTv1.setAdapter(stringArrayAdapterss);

//                          PickUpFrom(array);





                ArrayList<String> list2 = new ArrayList();
                collectDestinationData = (Map<String, List<LocationsResponse>>) stringObjectMap.get("2");
                for (Map.Entry<String, List<LocationsResponse>> entry : collectDestinationData.entrySet()) {
                    String mapKey = entry.getKey();
                    list2.add(mapKey);
                }
                int size2 = list2.size();
                String[] array2 = (String[]) list2.toArray(new String[size2]);

                SearchAdapter<String> stringArrayAdapters = new SearchAdapter<String>(QuickAddActivity.this, android.R.layout.simple_dropdown_item_1line, list2,10);
                autoTv2.setAdapter(stringArrayAdapters);
//              Destination(array2);







                ArrayList<String> list3 = new ArrayList();
                collectChargedTypeData = (Map<String, List<LocationsResponse>>) stringObjectMap.get("3");
                for (Map.Entry<String, List<LocationsResponse>> entry : collectChargedTypeData.entrySet()) {
                    String mapKey = entry.getKey();
                    list3.add(mapKey);
                }
                int size3 = list3.size();
                String[] array3 = (String[]) list3.toArray(new String[size3]);
                ChargedType(array3);




                ArrayList<String> list4 = new ArrayList();
                collectVehicleTypeData = (Map<String, List<LocationsResponse>>) stringObjectMap.get("4");
                for (Map.Entry<String, List<LocationsResponse>> entry : collectVehicleTypeData.entrySet()) {
                    String mapKey = entry.getKey();
                    list4.add(mapKey);
                }
                int size4 = list4.size();
                String[] array4 = (String[]) list4.toArray(new String[size4]);
                if (size4>0){
                    etVehicle.setText(array4[0]);
                    VechileTypeId = collectVehicleTypeData.get(array4[0]).get(0).getCode().toString();
                }

                VehicleType(array4);




//
//                Nocationalcollect = (Map<String, List<AddNocationResponse>>) stringObjectMap.get("5");
//                ArrayList<String> list5 = new ArrayList();
//                for (Map.Entry<String, List<AddNocationResponse>> entry : Nocationalcollect.entrySet()) {
//                    String mapKey = entry.getKey();
//                    list5.add(mapKey);
//                }
//                int size5 = list5.size();
//                String[] array5 = (String[]) list5.toArray(new String[size5]);
//               AddNocational(array5);

                Nocationalcollect = (Map<String, List<AddNocationResponse>>) stringObjectMap.get("5");
                ArrayList<String> list5 = new ArrayList();
                for (Map.Entry<String, List<AddNocationResponse>> entry : Nocationalcollect.entrySet()) {
                    String mapKey = entry.getKey();
                    list5.add(mapKey);
                }
                int size5 = list5.size();
                String[] array5 = (String[]) list5.toArray(new String[size5]);
                SearchAdapter<String> stringArrayAdapter = new SearchAdapter<>(QuickAddActivity.
                        this, android.R.layout.simple_dropdown_item_1line, list5,10);
                viewById.setAdapter(stringArrayAdapter);
            }

            @Override
            public void onDataFailCallBack(Object o) {
                ToastTool.showError(QuickAddActivity.this,"Net_Error");
            }
        });

        mQuickAddViewModel.LugData(new QuickAddViewModel.MyDataCallBack<int[]>() {
            @Override
            public void onDataSuccessCallBack(int[] ints) {
                LugType(ints);
            }

            @Override
            public void onDataFailCallBack(int[] ints) {

            }
        });


        mQuickAddViewModel.CardData(new QuickAddViewModel.MyDataCallBack<String[]>() {
            @Override
            public void onDataSuccessCallBack(String[] strings) {
                CadType(strings);
            }

            @Override
            public void onDataFailCallBack(String[] strings) {

            }
        });
        mQuickAddViewModel.PaxData(new QuickAddViewModel.MyDataCallBack<int[]>() {
            @Override
            public void onDataSuccessCallBack(int[] ints) {
                PaxType(ints);
            }

            @Override
            public void onDataFailCallBack(int[] ints) {

            }
        });


    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        RxHttpUtils.cancel("QuickAdd");
    }

    @Override
    protected void setListener() {
        cbSignboard.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    etSignboard.setFocusable(true);
                    etSignboard.setFocusableInTouchMode(true);
                    etSignboard.requestFocus();
                } else {
                    etSignboard.setFocusable(false);
                }
            }
        });


        cb_round_trip.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    RoundTrip=1;
                } else {
                    RoundTrip=0;
                }
            }
        });
//        autoTv1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                if (PickUpFromadapter.getItem(position).equals(autoTv2.getText().toString().trim())) {
//                    XToast.error(QuickAddActivity.this, getString(R.string.error_address)).show();
//                    autoTv1.setText("");
//                }
//            }
//        });
//        autoTv2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//                if (Destinationadapter.getItem(position).equals(autoTv1.getText().toString().trim())) {
//                    XToast.error(QuickAddActivity.this, getString(R.string.error_address)).show();
//                    autoTv2.setText("");
//                }
//            }
//        });


    }


    @SuppressLint("CheckResult")
    @OnClick({R2.id.qk_back, R2.id.tv_save, R2.id.et_vehicle, R2.id.btn_get_info, R2.id.et_date, R2.id.et_time, R2.id.rl_pax, R2.id.rl_lug, R2.id.auto_tv3,R2.id.auto_tv2,R2.id.auto_tv1,R2.id.auto_tv4,R2.id.et_card_type})
    public void onViewClicked(View view) {
        int id = view.getId();
        if (id == R.id.qk_back) {
            ActivityTool.getInstance().popOneActivity(this);
        } else if (id == R.id.tv_save) {

            String s1 = viewById.getText().toString();
            PickupFrom = autoTv1.getText().toString();
            Destination= autoTv2.getText().toString();

            if (Nocationalcollect!=null) {
                if (Nocationalcollect.containsKey(s1)){
                    LoginId = Nocationalcollect.get(s1).get(0).getLoginId().toString();
                }else{
                    LoginId = "";
                }

            }

            if (PickUpFromcollect!=null) {
                if (PickUpFromcollect.containsKey(PickupFrom)){
                    FromLocId = PickUpFromcollect.get(PickupFrom).get(0).getCode().toString();
                }else{
                    FromLocId = "";
                }

            }


            if (collectDestinationData!=null) {
                if (collectDestinationData.containsKey(Destination)){
                    ToLocId = collectDestinationData.get(Destination).get(0).getCode().toString();
                }else{
                    ToLocId = "";
                }

            }



            if (TextUtils.isEmpty(etDate.getText().toString().trim())
                    || TextUtils.isEmpty(etTime.getText().toString().trim())
                    || TextUtils.isEmpty(PickupFrom)
                    || TextUtils.isEmpty(Destination)
                    || TextUtils.isEmpty(etPassenger.getText().toString().trim())
                    || TextUtils.isEmpty(etVehicle.getText().toString().trim()))
            {
                XToast.error(QuickAddActivity.this, getString(R.string.xh_not_null)).show();

                return;
            } else {
                String s = etDate.getText().toString().trim() + " " + etTime.getText().toString();
//
                long l1 = TimeUtil.parseTime_dd(etDate.getText().toString().trim() + " " + etTime.getText().toString());
//                long l = TimeTool.stringTimeToLongTime(etDate.getText().toString().trim() +""+ etTime.getText().toString());
                String format = null;
                int check = 0;
                try {
                    format = TimeTool.format(l1, TimeTool.format7);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
                if (cbSignboard.isChecked()) {
                    check = 1;

                } else {
                    check = 0;
                }

                String trim1 = etPayId.getText().toString().trim();
                mQuickAddViewModel.Save(etGetinfo.getText().toString(),
                        etGetinfo.getText().toString(), etGetinfo.getText().toString(),

                        etPassenger.getText().toString(), Integer.parseInt(tvPax.getText().toString()),
                        Integer.parseInt(tvLug.getText().toString()), check, format, FromLocId, PickupFrom, ToLocId, Destination
                        , etOther.getText().toString(), ChargedTypeId, VechileTypeId, etSignboard.getText().toString(), etRemark.getText().toString(), s,LoginId,etItinerary.getText().toString().trim(),RoundTrip, trim,trim1,new QuickAddViewModel.MyDataCallBack<Object>() {
                            @Override
                            public void onDataSuccessCallBack(Object o) {
                                EventBus.getDefault().post(new RefEvent(true));

                                ActivityTool.getInstance().popOneActivity(QuickAddActivity.this);
                            }

                            @Override
                            public void onDataFailCallBack(Object o) {
                                XToast.error(QuickAddActivity.this, getString(R.string.bc_failed)).show();
                            }
                        });

            }


        } else if (id == R.id.btn_get_info) {
        } else if (id == R.id.et_date) {

            mTimePicker.show();
        } else if (id == R.id.et_time) {
            if (TextUtils.isEmpty(etDate.getText().toString())){
                XToast.error(QuickAddActivity.this,getString(R.string.date_not_null)).show();
            }else{
                mpickUpTime.show();
            }

        } else if (id == R.id.rl_pax) {
            mPaxType.show();
        } else if (id == R.id.rl_lug) {
            mLugType.show();
        } else if (id == R.id.auto_tv3) {
            if (mChargedType != null) {
                mChargedType.show();
            }


        } else if (id == R.id.et_vehicle) {
            if (mVehicleType != null) {
                mVehicleType.show();
            }

        }else if (id == R.id.auto_tv4){
//            if (mAddNocational != null) {
//                mAddNocational.show();
//            }
        }else if (id == R.id.auto_tv2){
            if (mDestination != null) {
                mDestination.show();
            }
        }else if (id == R.id.auto_tv1){
            if (mPickUpFrom != null) {
                mPickUpFrom.show();
            }
        }else if (id == R.id.et_card_type){
            if (mCadType != null) {
                mCadType.show();
            }
        }
    }



}
